<div>
    <span id="state">@state</span>
    <button id="tick" @onclick="Tick">Tick</button>
    <button id="tock" @onclick="Tock" disabled="@(!tockEnabled)">Tock</button>
</div>

@code
{
	public bool tockEnabled = false;
	public TaskCompletionSource<object?>? _tcs;
	public string state = "Stopped";

	public Task Tick(MouseEventArgs e)
	{
		if (_tcs is null)
		{
			_tcs = new TaskCompletionSource<object?>();

			state = "Started";
			tockEnabled = true;
			return _tcs.Task.ContinueWith(_ =>
			{
				state = "Stopped";
				_tcs = null;
			});
		}

		return Task.CompletedTask;
	}

	public void Tock(MouseEventArgs e)
	{
		tockEnabled = false;
		_tcs?.TrySetResult(null);
	}
}
